﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;
using System.Text;

namespace WooCoo.DataPortal.Server.Hosts.WcfChannel
{
    /// <summary>
    /// 服务终结点行为,目前为配置文件来为服务端终点扩展
    /// </summary>
    /// <example>
    /// <extensions>
    /// <behaviorExtensions>
    /// <客户端>
    /// <add name="WcdfClient" type="Wcdf.DataPortalClient.Wcf.ClientEndpointBehavior, Wcdf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7a885d56250d4099"/>
    /// <服务端>
    /// <add name="WcdfServer" type="Wcdf.Server.WcfHost.ServiceEndpointBehavior, Wcdf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7a885d56250d4099"/>
    /// </behaviorExtensions>
    /// </extensions>
    /// </example>
    public class ServiceEndpointBehavior : BehaviorExtensionElement, IEndpointBehavior
    {
        #region IEndpointBehavior 成员

        public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {

        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
        {

        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new ServiceDispatchMessageInspector());
            //错误处理模块
            endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new ServiceErrorHandler());
        }

        public void Validate(ServiceEndpoint endpoint)
        {
        }

        #endregion

        #region override BehaviorExtensionElement method
        public override Type BehaviorType
        {
            get { return typeof(ServiceEndpointBehavior); }
        }

        protected override object CreateBehavior()
        {
            return new ServiceEndpointBehavior();
        }
        #endregion
    }
}
